import { defineStore } from 'pinia'
import {
  getAdressGoodsSale,
  getCatregoryGoodsCount,
  getCatregoryGoodsFavor,
  getCatregoryGoodsSale
} from '@/service/main/dashboard'

// 类型
// 商品数量统计 商品销售统计 商品喜好统计 地区销售统计
interface IDashboardState {
  categoryGoodsCount: any[]
  categoryGoodsSale: any[]
  categoryGoodsFavor: any[]
  addressGoodsSale: any[]
}

export const useDashboardStore = defineStore('dashboard', {
  state: (): IDashboardState => ({
    categoryGoodsCount: [],
    categoryGoodsSale: [],
    categoryGoodsFavor: [],
    addressGoodsSale: []
  }),

  actions: {
    async getDashboardDataAction() {
      // 把这些图表的信息请求下来然后保存到
      const categoryCountResult = await getCatregoryGoodsCount()
      this.categoryGoodsCount = categoryCountResult.data // 保存信息的

      const categorySaleResult = await getCatregoryGoodsSale()
      this.categoryGoodsSale = categorySaleResult.data

      const categoryFavorResult = await getCatregoryGoodsFavor()
      this.categoryGoodsFavor = categoryFavorResult.data

      const addresSaleResult = await getAdressGoodsSale()
      this.addressGoodsSale = addresSaleResult.data
    }
  },

  getters: {}
})
